package com.ftg.learn.chapter10.jdbc;


import com.alibaba.fastjson2.JSONArray;

import java.util.List;

/**
 * DAO : data access object : 数据访问对象 dao 都是用来操作数据 sql
 *
 * @author kangjx
 * @createTime 2022/7/21
 */
public class StudentDao extends SimpleJdbcUtil<Student> {

    /**
     * 查询学生表里面的全部数据
     *
     * @return
     */
    public List<Student> showAllStudent() {
        return super.queryPojo("select * from student");
    }

   public String queryForJsonTest() {
        return super.queryPojoForJson("select * from student");
    }

    /**
     * 查询学生表里面的全部数据
     *
     * @return
     */
    public List<Student> showParameter(String sname) {
        return super.queryPojo("select * from student where sname like concat(?,'%')", sname);
    }

    public int saveStudent(String sno, String sname, int sage, String ssex) {
        return super.dml("insert into student(sno,sname,sage,ssex) values(?,?,?,?)", sno, sname, sage, ssex);
    }

    public int saveStu1(Student s1) {
        return super.save(s1);
    }

    public boolean saveBatch(String[] sql,Object[]...obj) {
        return super.bathDml(sql,obj);
    }


    public int deleteFor(){
        return super.deleteByParam(()->"where sname like concat(?,'%')","a");
    }

    public int deleteById(Integer id){
        return super.deleteById(id);
    }

    public static void main(String[] args) {
        StudentDao s = new StudentDao();
        String[] sql = {"insert into student(sno) values(?)","insert into teacher(tno) values(?)"};
        boolean t = s.saveBatch(sql,new Object[]{"s1234"},new Object[]{"s9999"});
        System.out.println(t);
    }

}
